package com.xiu.jvm.gc;

public class FinalizeEscapeGC {
	private static FinalizeEscapeGC SAVE_HOOK=null;
	
	@Override
	protected void finalize() throws Throwable {
		super.finalize();
		System.out.println("finalize method excuted!");
		SAVE_HOOK=this;
	}
	public static void main(String[] args) throws Exception {
		SAVE_HOOK=new FinalizeEscapeGC();
		SAVE_HOOK=null;
		System.gc();
		Thread.sleep(500);
		if(SAVE_HOOK!=null) {
			System.out.println("alive");
		}else {
			System.out.println("dead");
		}
		SAVE_HOOK=null;
		System.gc();
		Thread.sleep(500);
		if(SAVE_HOOK!=null) {
			System.out.println("alive");
		}else {
			System.out.println("dead");
		}
	}

}
